#include <Box2D.h>
#include "common.h"
#include "b2AABB.h"

#ifdef __cplusplus
extern "C" {
#endif

JNIEXPORT void JNICALL Java_b2AABB_jni_1b2AABB_1release
  (JNIEnv *env, jclass cls, jint me)
{
	b2AABB* aabb = (b2AABB*)me;
	delete aabb;
}

JNIEXPORT jint JNICALL Java_b2AABB_jni_1b2AABB
  (JNIEnv *env, jclass cls)
{
	b2AABB* aabb = new b2AABB();
	return (jint)aabb;
}

JNIEXPORT jboolean JNICALL Java_b2AABB_jni_1b2AABB_1IsValid
  (JNIEnv *env, jclass cls, jint me)
{
	b2AABB* aabb = (b2AABB*)me;
	return aabb->IsValid();
}

JNIEXPORT jint JNICALL Java_b2AABB_jni_1b2AABB_1GetCenter
  (JNIEnv *env, jclass cls, jint me)
{
	b2AABB* aabb = (b2AABB*)me;
	b2Vec2 center = aabb->GetCenter();
	b2Vec2* vector = new b2Vec2(center.x, center.y);

	return (jint)vector;
}

JNIEXPORT jint JNICALL Java_b2AABB_jni_1b2AABB_1GetExtents
  (JNIEnv *env, jclass cls, jint me)
{
	b2AABB* aabb = (b2AABB*)me;
	b2Vec2 center = aabb->GetExtents();
	b2Vec2* vector = new b2Vec2(center.x, center.y);

	return (jint)vector;
}

JNIEXPORT jfloat JNICALL Java_b2AABB_jni_1b2AABB_1GetPerimeter
  (JNIEnv *env, jclass cls, jint me)
{
	b2AABB* aabb = (b2AABB*)me;
	return aabb->GetPerimeter();
}

JNIEXPORT void JNICALL Java_b2AABB_jni_1b2AABB_1Combine__II
  (JNIEnv *env, jclass cls, jint me, jint aabb)
{
	b2AABB* b2aabb = (b2AABB*)me;
	b2AABB* other = (b2AABB*)aabb;

	b2aabb->Combine(*other);
}

JNIEXPORT void JNICALL Java_b2AABB_jni_1b2AABB_1Combine__III
  (JNIEnv *env, jclass cls, jint me, jint aabb1_addr, jint aabb2_addr)
{
	b2AABB* aabb = (b2AABB*)me;
	b2AABB* aabb1 = (b2AABB*)aabb1_addr;
	b2AABB* aabb2 = (b2AABB*)aabb2_addr;

	aabb->Combine(*aabb1, *aabb2);
}


JNIEXPORT jboolean JNICALL Java_b2AABB_jni_1b2AABB_1Contains
  (JNIEnv *env, jclass cls, jint me, jint aabb_addr)
{
	b2AABB* aabb = (b2AABB*)me;
	b2AABB* other = (b2AABB*)aabb_addr;

	return aabb->Contains(*other);
}

JNIEXPORT jboolean JNICALL Java_b2AABB_jni_1b2AABB_1RayCast
  (JNIEnv *env, jclass cls, jint me, jint output_addr, jint input_addr)
{
	b2AABB* aabb = (b2AABB*)me;
	b2RayCastOutput* output = (b2RayCastOutput*)output_addr;
	b2RayCastInput* input = (b2RayCastInput*)input_addr;

	return aabb->RayCast(output, *input);
}


#ifdef __cplusplus
}
#endif
